import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLayeredPane;
import javax.swing.JTextArea;


public class NodeShopInterface extends JLayeredPane{

	private static final long serialVersionUID = 1L;
	JTextArea textArea = new JTextArea();
	Font font = new Font("Verdana", Font.PLAIN, 18);
	ArrayList<ItemKind> listWithItems = new ArrayList<ItemKind>();
	ArrayList<ItemKind> listWithShopItems = new ArrayList<ItemKind>();
	int finalInventoryLevel = 0;
	int currentInventoryLevel = 0;
	final int ENLARGE_VALUE = 100;
	String[][] playerInventoryLevels;
	String[][] shopInventoryLevels;
	MapNode node;
	Player player;
	InterfaceFrame frame;
	CustomButton buy = new CustomButton("Köp");
	CustomButton sell = new CustomButton("Sälj");
	
	CustomButton back = new CustomButton("Tillbaka");
	CustomButton item1 = new CustomButton("1");
	CustomButton item2 = new CustomButton("2");
	CustomButton item3 = new CustomButton("3");
	CustomButton item4 = new CustomButton("4");
	CustomButton item5 = new CustomButton("5");
	
	CustomArrowButton up = new CustomArrowButton("Up");
	CustomArrowButton down = new CustomArrowButton("Down");
	
	Inventory shopInventory;
	
	boolean buyMode = false;
	
	NodeShopInterface(Player player, InterfaceFrame frame){
		
		this.player = player;
		this.frame=frame;
		
		back.addActionListener(new ItemListener());
		item1.addActionListener(new ItemListener());
		item2.addActionListener(new ItemListener());
		item3.addActionListener(new ItemListener());
		item4.addActionListener(new ItemListener());
		item5.addActionListener(new ItemListener());
		buy.addActionListener(new ItemListener());
		sell.addActionListener(new ItemListener());
		down.addActionListener(new ItemListener());
		up.addActionListener(new ItemListener());
		
		item1.setMultiClickThreshhold(500);
		item2.setMultiClickThreshhold(500);
		item3.setMultiClickThreshhold(500);
		item4.setMultiClickThreshhold(500);
		item5.setMultiClickThreshhold(500);
		back.setMultiClickThreshhold(500);
		buy.setMultiClickThreshhold(500);
		sell.setMultiClickThreshhold(500);
		down.setMultiClickThreshhold(500);
		up.setMultiClickThreshhold(500);
		
		item1.addMouseListener(new TheMouseListener());
		item2.addMouseListener(new TheMouseListener());
		item3.addMouseListener(new TheMouseListener());
		item4.addMouseListener(new TheMouseListener());
		item5.addMouseListener(new TheMouseListener());
		back.addMouseListener(new TheMouseListener());		
		buy.addMouseListener(new TheMouseListener());
		sell.addMouseListener(new TheMouseListener());
		down.addMouseListener(new TheMouseListener());
		up.addMouseListener(new TheMouseListener());
		
		getTextArea();
	}
	
	public void buyItem(){
		
	}
	
	public void getShopImage(String path){
		if(frame.nface.imageLabel!=null)
			frame.nface.imageLabel.removeAll();
		frame.nface.imageLabel.setIcon(new ImageIcon(getClass().getResource(path)));
	}
	
	public void getBuySellPanel(){
		currentInventoryLevel = 0;
		shopInventory = frame.nface.node.getShopInventory();
		listWithShopItems = shopInventory.getItems();
		frame.nface.textArea.setText("Är ni intresserad av mina varor?");
		
		if(back!=null){
			frame.nface.popOptions.remove(back);
		}
		
		if(up!=null){
			frame.nface.popOptions.remove(up);
		}
		
		if(down!=null){
			frame.nface.popOptions.remove(down);
		}
		
		if(item1!=null){
			frame.nface.popOptions.remove(item1);
		}
		if(item2!=null){
			frame.nface.popOptions.remove(item2);
		}
		if(item3!=null){
			frame.nface.popOptions.remove(item3);
		}
		if(item4!=null){
			frame.nface.popOptions.remove(item4);
		}
		if(item5!=null){
			frame.nface.popOptions.remove(item5);
		}
		
		frame.getContentPane().repaint();
		frame.nface.popOptions.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		buy.setFont(font);
		sell.setFont(font);
		frame.nface.popOptions.add(buy);
		frame.nface.popOptions.add(sell);
		frame.nface.popOptions.repaint();
	}
	
	public void showPlayerInventoryLevel(int level){
		frame.nface.popOptions.remove(buy);
		frame.nface.popOptions.remove(sell);
		createPlayerInventoryLevels();
		frame.nface.popOptions.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		
		frame.nface.popOptions.add(back);
	
		if(playerInventoryLevels[level][0] != null)
			item1.setText(playerInventoryLevels[level][0]);
		if(playerInventoryLevels[level][1] != null)
			item2.setText(playerInventoryLevels[level][1]);
		if(playerInventoryLevels[level][2] != null)
			item3.setText(playerInventoryLevels[level][2]);
		if(playerInventoryLevels[level][3] != null)
			item4.setText(playerInventoryLevels[level][3]);
		if(playerInventoryLevels[level][4] != null)
			item5.setText(playerInventoryLevels[level][4]);
		
		if(playerInventoryLevels[level][0] != null)
			frame.nface.popOptions.add(item1);
		else
			frame.nface.popOptions.remove(item1);
		if(playerInventoryLevels[level][1] != null)
			frame.nface.popOptions.add(item2);
		else
			frame.nface.popOptions.remove(item2);
		if(playerInventoryLevels[level][2] != null)
			frame.nface.popOptions.add(item3);
		else
			frame.nface.popOptions.remove(item3);
		if(playerInventoryLevels[level][3] != null)
			frame.nface.popOptions.add(item4);
		else
			frame.nface.popOptions.remove(item4);
		if(playerInventoryLevels[level][4] != null)
			frame.nface.popOptions.add(item5);
		else
			frame.nface.popOptions.remove(item5);
		if(currentInventoryLevel != finalInventoryLevel && listWithItems.size() >5)
			frame.nface.popOptions.add(down);
		else
			frame.nface.popOptions.remove(down);
		if(currentInventoryLevel != 0)
			frame.nface.popOptions.add(up);
		else
			frame.nface.popOptions.remove(up);
		
		//((JComponent) frame.getContentPane()).revalidate();
		frame.getContentPane().repaint();
	}
	
	public void showShopInventoryLevel(int level){
		
		frame.nface.popOptions.remove(buy);
		frame.nface.popOptions.remove(sell);
		createShopInventoryLevels();
		frame.nface.popOptions.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		
		if(shopInventoryLevels[level][0] != null)
			item1.setText(shopInventoryLevels[level][0]);
		if(shopInventoryLevels[level][1] != null)
			item2.setText(shopInventoryLevels[level][1]);
		if(shopInventoryLevels[level][2] != null)
			item3.setText(shopInventoryLevels[level][2]);
		if(shopInventoryLevels[level][3] != null)
			item4.setText(shopInventoryLevels[level][3]);
		if(shopInventoryLevels[level][4] != null)
			item5.setText(shopInventoryLevels[level][4]);

		frame.nface.popOptions.add(back);
		
		if(shopInventoryLevels[level][0] != null)
			frame.nface.popOptions.add(item1);
		else
			frame.nface.popOptions.remove(item1);
		if(shopInventoryLevels[level][1] != null)
			frame.nface.popOptions.add(item2);
		else
			frame.nface.popOptions.remove(item2);
		if(shopInventoryLevels[level][2] != null)
			frame.nface.popOptions.add(item3);
		else
			frame.nface.popOptions.remove(item3);
		if(shopInventoryLevels[level][3] != null)
			frame.nface.popOptions.add(item4);
		else
			frame.nface.popOptions.remove(item4);
		if(shopInventoryLevels[level][4] != null)
			frame.nface.popOptions.add(item5);
		else
			frame.nface.popOptions.remove(item5);
		
		if(currentInventoryLevel != finalInventoryLevel  && listWithShopItems.size() >5)
			frame.nface.popOptions.add(down);
		else
			frame.nface.popOptions.remove(down);
		
		if(currentInventoryLevel != 0)
			frame.nface.popOptions.add(up);
		else
			frame.nface.popOptions.remove(up);
		
		frame.getContentPane().repaint();

	}	
	
	public void createShopInventoryLevels(){
    	
    	shopInventoryLevels = new String[20][5];
    	listWithShopItems = shopInventory.getItems();
    	
    	//Undersöker vilken sista Leveln är.
    	if(listWithShopItems.size()%5 == 0)
    		finalInventoryLevel = listWithShopItems.size()/5 - 1;
    	else
    		finalInventoryLevel = listWithShopItems.size()/5;
    	
    	String level[] = new String[5];
    	int index = 0;
    	
    	for(int i = 0; i <= finalInventoryLevel; i++){
    		
    		//Om inventoryLevels arrayen är full, skapa en större!
    		if(shopInventoryLevels.length <= index)
    			enlargeShop();
    		
    		//Lopar fram en sträng till varje index som innehåller hur många items och namnet.
    		for(int j = 0; j < 5; j++){
    			
    			level[i] = shopInventory.itemCount(listWithShopItems.get(index)) + "x " + new Item(listWithShopItems.get(index)).getName();
    			shopInventoryLevels[i][j] = level[i];
    			index++;
    			
    			//Ifall vi kommit till slutet bryt.
    			if(index >= listWithShopItems.size()){
    				break;
    			}
    			
    		}
    		
    	}
	}
	
	public void createPlayerInventoryLevels(){
    	
    	playerInventoryLevels = new String[20][5];
    	listWithItems = player.inventory.getItems();
    	
    	//Undersöker vilken sista Leveln är.
    	if(listWithItems.size()%5 == 0)
    		finalInventoryLevel = listWithItems.size()/5 - 1;
    	else
    		finalInventoryLevel = listWithItems.size()/5;
    	
    	String level[] = new String[5];
    	int index = 0;
    	
    	for(int i = 0; i <= finalInventoryLevel; i++){
    		
    		//Om inventoryLevels arrayen är full, skapa en större!
    		if(playerInventoryLevels.length <= index)
    			enlargePlayer();
    		
    		//Lopar fram en sträng till varje index som innehåller hur många items och namnet.
    		for(int j = 0; j < 5; j++){
    			
    			level[i] = player.inventory.itemCount(listWithItems.get(index)) + "x " + new Item(listWithItems.get(index)).getName();
    			playerInventoryLevels[i][j] = level[i];
    			index++;
    			
    			//Ifall vi kommit till slutet bryt.
    			if(index >= listWithItems.size()){
    				break;
    			}
    			
    		}
    		
    	}
	}
	private void enlargeShop(){
    	
    	int newLength = 1 + shopInventoryLevels.length + ENLARGE_VALUE * shopInventoryLevels.length/100;
    	String[][] newArray = new String[newLength][5];
    	
    	for(int index = 0; index < shopInventoryLevels.length; index++){
    		for(int j = 1; j < 5; j++)
    			newArray[index][j] = shopInventoryLevels[index][j];
    	}
    	
    	shopInventoryLevels = newArray;
    	
    }
	private void enlargePlayer(){
    	
    	int newLength = 1 + playerInventoryLevels.length + ENLARGE_VALUE * playerInventoryLevels.length/100;
    	String[][] newArray = new String[newLength][5];
    	
    	for(int index = 0; index < playerInventoryLevels.length; index++){
    		for(int j = 1; j < 5; j++)
    			newArray[index][j] = playerInventoryLevels[index][j];
    	}
    	
    	playerInventoryLevels = newArray;
    	
    }
	
	public void getTextArea(){
	}
	
	public boolean hasMoney(Item item){
		
		if(player.money >= item.buyprice())
			return true;
		else
			return false;
	}
	
	
	private class ItemListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource().equals(buy)){
				buyMode = true;
				currentInventoryLevel = 0;
				showShopInventoryLevel(0);
			}
			else if(e.getSource().equals(sell)){
				buyMode = false;
				currentInventoryLevel = 0;
				showPlayerInventoryLevel(0);
			}
			
			else if(e.getSource().equals(back)){
				if(currentInventoryLevel != finalInventoryLevel  && listWithShopItems.size() >5)
					frame.nface.popOptions.remove(down);
				if(currentInventoryLevel != 0)
					frame.nface.popOptions.remove(up);
				getBuySellPanel();
			}
			
			else if(e.getSource().equals(item1) && buyMode){
				int index = currentInventoryLevel * 5;
				if(hasMoney(new Item(listWithShopItems.get(index)))){
					player.money=player.money-new Item(listWithShopItems.get(index)).buyprice();
					player.inventory.addItem(listWithShopItems.get(index), 1);
					frame.nface.node.inventory.removeItem(listWithShopItems.get(index), 1);
					showShopInventoryLevel(currentInventoryLevel);
				}
				
			}
			else if(e.getSource().equals(item2) && buyMode){
				int index = currentInventoryLevel * 5 + 1;
				if(hasMoney(new Item(listWithShopItems.get(index)))){
					player.money=player.money-new Item(listWithShopItems.get(index)).buyprice();
					player.inventory.addItem(listWithShopItems.get(index), 1);
					frame.nface.node.inventory.removeItem(listWithShopItems.get(index), 1);
					showShopInventoryLevel(currentInventoryLevel);
				}	
			}
			else if(e.getSource().equals(item3) && buyMode){
				int index = currentInventoryLevel * 5 + 2;
				if(hasMoney(new Item(listWithShopItems.get(index)))){
					player.money=player.money-new Item(listWithShopItems.get(index)).buyprice();
					player.inventory.addItem(listWithShopItems.get(index), 1);
					frame.nface.node.inventory.removeItem(listWithShopItems.get(index), 1);
					showShopInventoryLevel(currentInventoryLevel);
				}	
			}
			else if(e.getSource().equals(item4) && buyMode){
				int index = currentInventoryLevel * 5 + 3;
				if(hasMoney(new Item(listWithShopItems.get(index)))){
					player.money=player.money-new Item(listWithShopItems.get(3)).buyprice();
					player.inventory.addItem(listWithShopItems.get(3), 1);
					frame.nface.node.inventory.removeItem(listWithShopItems.get(3), 1);
					showShopInventoryLevel(currentInventoryLevel);
				}	
			}
			else if(e.getSource().equals(item5) && buyMode){
				int index = currentInventoryLevel * 5 + 4;
				if(hasMoney(new Item(listWithShopItems.get(index)))){
					player.money=player.money-new Item(listWithShopItems.get(index)).buyprice();
					player.inventory.addItem(listWithShopItems.get(index), 1);
					frame.nface.node.inventory.removeItem(listWithShopItems.get(index), 1);
					showShopInventoryLevel(currentInventoryLevel);
				}	
			}
			else if(e.getSource().equals(down) && buyMode){
				currentInventoryLevel++;
				showShopInventoryLevel(currentInventoryLevel);
			}
			else if(e.getSource().equals(up) && buyMode){
				currentInventoryLevel--;
				showShopInventoryLevel(currentInventoryLevel);
			}
			
			else if(e.getSource().equals(item1) && !buyMode){
				int index = currentInventoryLevel * 5;
				player.money=player.money + new Item(listWithItems.get(index)).sellprice();
				player.inventory.removeItem(listWithItems.get(index), 1);
				frame.nface.node.inventory.addItem(listWithItems.get(index), 1);
				showPlayerInventoryLevel(currentInventoryLevel);
					
			}
			else if(e.getSource().equals(item2) && !buyMode){
				int index = currentInventoryLevel * 5 + 1;
				player.money=player.money + new Item(listWithItems.get(index)).sellprice();
				player.inventory.removeItem(listWithItems.get(index), 1);
				frame.nface.node.inventory.addItem(listWithItems.get(index), 1);
				showPlayerInventoryLevel(currentInventoryLevel);
					
			}
			else if(e.getSource().equals(item3) && !buyMode){
				int index = currentInventoryLevel * 5 + 2;
				player.money=player.money + new Item(listWithItems.get(index)).sellprice();
				player.inventory.removeItem(listWithItems.get(index), 1);
				frame.nface.node.inventory.addItem(listWithItems.get(index), 1);
				showPlayerInventoryLevel(currentInventoryLevel);
					
			}
			else if(e.getSource().equals(item4) && !buyMode){
				int index = currentInventoryLevel * 5 + 3;
				player.money=player.money + new Item(listWithItems.get(index)).sellprice();
				player.inventory.removeItem(listWithItems.get(index), 1);
				frame.nface.node.inventory.addItem(listWithItems.get(index), 1);
				showPlayerInventoryLevel(currentInventoryLevel);
					
			}
			else if(e.getSource().equals(item5) && !buyMode){
				int index = currentInventoryLevel * 5 + 4;
				player.money=player.money + new Item(listWithItems.get(index)).sellprice();
				player.inventory.removeItem(listWithItems.get(index), 1);
				frame.nface.node.inventory.addItem(listWithItems.get(index), 1);
				showPlayerInventoryLevel(currentInventoryLevel);
					
			}
			else if(e.getSource().equals(down) && !buyMode){
				currentInventoryLevel++;
				showPlayerInventoryLevel(currentInventoryLevel);
			}
			else if(e.getSource().equals(up) && !buyMode){
				currentInventoryLevel--;
				showPlayerInventoryLevel(currentInventoryLevel);
			}
			((JComponent) frame.getContentPane()).revalidate();
			frame.getContentPane().repaint();
		}
		
	}
	private class CustomButton extends JButton{
		
		private static final long serialVersionUID = 1L;
		CustomButton(String str){
			this.setContentAreaFilled(false);
			this.setForeground(Color.BLACK);
			setText(str);
			setName(str);
		}
		
		@Override
		public Dimension getMinimumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getMaximumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getPreferredSize(){
			return new Dimension(306,50);	
		}
		
		
	}
	
	private class CustomArrowButton extends JButton{
		
		private static final long serialVersionUID = 1L;
		CustomArrowButton(String str){
			this.setContentAreaFilled(false);
			this.setForeground(Color.BLACK);
			setText(str);
			setName(str);
		}
		
		@Override
		public Dimension getMinimumSize(){
			return new Dimension(153,50);	
		}
		@Override
		public Dimension getMaximumSize(){
			return new Dimension(153,50);	
		}
		@Override
		public Dimension getPreferredSize(){
			return new Dimension(153,50);	
		}
		
	}
	
	private class TheMouseListener implements MouseListener{

		@Override
		public void mouseClicked(MouseEvent e) {
			if(e.getComponent().getName().equals("1") && buyMode){
				int index = currentInventoryLevel * 5;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("2") && buyMode){
				int index = currentInventoryLevel * 5 + 1;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("3") && buyMode){
				int index = currentInventoryLevel * 5 + 2;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("4") && buyMode){
				int index = currentInventoryLevel * 5 + 3;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("5") && buyMode){
				int index = currentInventoryLevel * 5 + 4;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("1") && !buyMode){
				int index = currentInventoryLevel * 5;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("2") && !buyMode){
				int index = currentInventoryLevel * 5 + 1;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("3") && !buyMode){
				int index = currentInventoryLevel * 5 + 2;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("4") && !buyMode){
				int index = currentInventoryLevel * 5 + 3;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("5") && !buyMode){
				int index = currentInventoryLevel * 5 + 4;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			if(e.getComponent().getName().equals("Tillbaka") && buyMode){
				frame.nface.textArea.setText("Tillbaka");
				frame.getContentPane().repaint();
			}

			else if(e.getComponent().getName().equals("1") && buyMode){
				int index = currentInventoryLevel * 5;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("2") && buyMode){
				int index = currentInventoryLevel * 5 + 1;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("3") && buyMode){
				int index = currentInventoryLevel * 5 + 2;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("4") && buyMode){
				int index = currentInventoryLevel * 5 + 3;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("5") && buyMode){
				int index = currentInventoryLevel * 5 + 4;
				frame.nface.textArea.setText(new Item(listWithShopItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Kostnad: " + new Item(listWithShopItems.get(index)).buyprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("1") && !buyMode){
				int index = currentInventoryLevel * 5;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("2") && !buyMode){
				int index = currentInventoryLevel * 5 + 1;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("3") && !buyMode){
				int index = currentInventoryLevel * 5 + 2;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("4") && !buyMode){
				int index = currentInventoryLevel * 5 + 3;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
			else if(e.getComponent().getName().equals("5") && !buyMode){
				int index = currentInventoryLevel * 5 + 4;
				frame.nface.textArea.setText(new Item(listWithItems.get(index)).description + '\n' + 
											"Guld: " + player.money + '\n' +
											"Marknadspris: " + new Item(listWithItems.get(index)).sellprice());
				frame.getContentPane().repaint();
			}
		}

		@Override
		public void mouseExited(MouseEvent e) {
			frame.getContentPane().repaint();
		}

		@Override
		public void mousePressed(MouseEvent e) {
			frame.nface.popPrime.show(frame, 50, 55);
		}

		@Override
		public void mouseReleased(MouseEvent arg0) {
		}
		
	}
}
